package com.lk.labsystem.controller;

import com.lk.labsystem.Dao.RightMapper;
import com.lk.labsystem.pojo.Right;
import com.lk.labsystem.service.RightService;
import com.lk.labsystem.utils.ResultOBJ;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/adminapi/rights")
public class RightController {
    //自动注入
    @Autowired
    RightService rightService;
    //获取权限
    @GetMapping
    public List<Right> getRightList() {
        return rightService.getRightList();
    }
    //更新权内容
    @PutMapping(value = "/{id}")
    public ResultOBJ updateRightList(@PathVariable Integer id, @RequestBody Right right) {
        try {
            right.setId(id);
            rightService.updateRightList(right);
            return ResultOBJ.UPDATE_SUCCESS;
        } catch (Exception e) {
            return ResultOBJ.UPDATE_ERROR;
        }
    }
    //删除权限
    @DeleteMapping(value = "/{id}")
    public ResultOBJ deleteRightList(@PathVariable Integer id){
        try {
            rightService.deleteRightList(id);
            return ResultOBJ.DELETE_SUCCESS;
        } catch (Exception e) {
            return ResultOBJ.DELETE_ERROR;
        }
    }
}
